package com.ysjweb.dish.pojo;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;

import java.util.*;

public class RequestWrapper extends HttpServletRequestWrapper {
    private HashMap<String,String> Headers=new HashMap<>();
    public RequestWrapper(HttpServletRequest request) {
        super(request);
    }
    public void addHeader(String name, String value) {
        Headers.put(name, value);
    }

    @Override
    public String getHeader(String name) {
        return (Headers.containsKey(name)) ? Headers.get(name) : super.getHeader(name);
    }
    @Override
    public Enumeration<String> getHeaders(String name) {
        List<String> values = Collections.list(super.getHeaders(name));
        if (Headers.containsKey(name)) {
            values.add(Headers.get(name));
        }
        return Collections.enumeration(values);
    }
    @Override
    public Enumeration<String> getHeaderNames() {
        Set<String> AllNames = new HashSet<>(Collections.list(super.getHeaderNames()));
        AllNames.addAll(Headers.keySet());
        return Collections.enumeration(AllNames);
    }
}
